﻿using MediatR;
using T_vehicle.API.Application.Command.AccidentCommand;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.AccidentCommandHandlers
{
    public class PDelAccidentCommandHandlers:IRequestHandler<PDelAccidentCommand,int>
    {
        private readonly IAccidentRepository accidentRepository;

        public PDelAccidentCommandHandlers(IAccidentRepository accidentRepository)
        {
            this.accidentRepository = accidentRepository;
        }

        public async Task<int> Handle(PDelAccidentCommand request, CancellationToken cancellationToken)
        {
            var Id = request.AccidentId.Split(',').Select(x => Convert.ToInt32(x));
            var list = await accidentRepository.GetAsync(x => Id.Contains(x.AccidentId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await accidentRepository.UpdateAsyncRange(list);

        }
    }
}
